function userRegister() {
    let name = $("#name").val();
    let email = $("#email").val();
    let verification = $("#verification").val();
    let password = $("#password").val();
    let checked = $("#policy").prop('checked');
    let policy = 0;
    if(checked)
    {
        policy = 1;
    }
    $.post("/blog/user/register",
        {
            name:name,
            email:email,
            verification:verification,
            password:password,
            policy:policy
        },
        function(data,status){
            //提示语隐藏,出现弹出层
            let arr = new Array('name','email','verification','password','policy');
            $.each(arr,function(index,value){
                $("#invalid-"+value).css("display",'none');
            });
            if (status == 'success')
            {
                if(data.message != 'success')
                {
                    $.each(arr,function(index,value){
                        if(data['data'][value])
                        {
                            $("#invalid-"+value).html(data['data'][value]).css("display",'block');
                        }
                    });
                }
                else
                {
                    if(data['data']['token'])
                    {
                        $("#modal-success").css('display','block');
                        $("#modal-success #experience-now").attr("href",data['data']['back_url']);
                        //定时跳转
                        let timer = setInterval(function () {
                            showCountDown(timer,3)
                        }, 1000);
                        setTimeout(function () {
                            window.location.href = data['data']['back_url'];
                        } , 3000);
                    }
                    else
                    {
                        $("#modal-danger").css('display','block');
                    }
                }
            }
            else
            {
                $("#modal-danger").css('display','block');
            }
        },"json");
};
function showCountDown(timer,after)
{
    let experience_now_after =$("#experience-now-after");
    let experience_now_time = $("#experience-now-time");
    let time = parseInt(experience_now_after.val());
    time++;
    if (time > after)
    {
        clearInterval(timer);//需要清除计时器
    }
    else
    {
        experience_now_time.html(time+'s');
        experience_now_after.val(time);
    }
}
function showPassword()
{
    let password_type = $("#password").prop("type");
    if(password_type == 'text')
    {
        $("#password").prop("type","password");
    }
    else
    {
        $("#password").prop("type","text");
    }
}
function getVerification()
{
    //邮件发送验证码
    let email = $("#email").val();
    if(email.length == 0)
    {
        $("#modal-small").css('display','block');
        $("#modal-small #modal-message").html("请输入邮箱");
        return false;
    }
    $.post("/blog/user/get_verification",
        {
            email:email
        },
        null,
        "json"
    );
    $("#get-verification").attr('disabled',true);
    let timer = setInterval(function () {
        verificationCountDown(timer,30)
    }, 1000);
}
function verificationCountDown(timer,after)
{
    let get_verification_after =$("#get-verification-after");
    let get_verification = $("#get-verification");
    let time = parseInt(get_verification_after.val());
    time++;
    if (time > after)
    {
        get_verification_after.val(0);
        get_verification.attr('disabled',false).html('获取验证码');
        clearInterval(timer);//需要清除计时器
    }
    else
    {
        get_verification.html('已发送('+time+'s)');
        get_verification_after.val(time);
    }
}
$("#register-success").click(function () {
    $("#modal-success").css('display','none');
});
$("#register-fail").click(function () {
    $("#modal-danger").css('display','none');
});
$("#modal-close").click(function () {
    $("#modal-small").css('display','none');
});
$(".modal").click(function () {
    $(".modal").css('display','none');
});

